package com.nt.train.config;

import com.nt.train.dto.Dog;
import com.nt.train.dto.Teacher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hlf
 * @version 1.0
 * @date 2022/8/3 14:32
 */
@Configuration
//不同路径下扫描包名 方式-
//@ComponentScan("com.demo.bean")
//Import注解导入，可以理解为嵌套，以前用xml的时候可以嵌套，注解也支持嵌套 方式2
//@Import(Dog.class)
public class SpringBeanConfiguration {

    //bean 注入 方式 3
    @Bean
    public Teacher getTeacher(){
        return new Teacher();
    }

    //定义初始化
    @Bean
    public Map<String,Integer> integerMap(){
        Map<String,Integer> integerMap = new HashMap<String, Integer>();
        integerMap.put("map-1",1);
        integerMap.put("map-2",2);
        return integerMap;
    }

    @Bean
    public List<String> stringList(){
        List<String> stringList = new ArrayList<String>();
        stringList.add("List-1");
        stringList.add("List-2");
        return stringList;
    }


    @Bean
    public Integer integer1(){
        return 1;
    }

    @Bean
    //通过该注解设定Bean注入的优先级，不一定连续数字
    @Order(34)
    public String string1(){
        return "String-1";
    }

//    @Bean
//    @Order(14)
//    public String string2(){
//        return "String-2";
//    }


}
